package com.pcjavanet.collect.mes.dao;

import java.util.LinkedList;
import java.util.List;

import org.springframework.dao.DataAccessException;

import com.pcjavanet.collect.mes.to.ChartData;
import com.pcjavanet.collect.mes.to.DiscreteData;
import com.pcjavanet.collect.mes.to.ParetoData;
import com.pcjavanet.collect.mes.to.SpcParetoException;
import com.pcjavanet.collect.mes.to.SpcRelParetoDataException;

/**
 * interface DiscreteDataDao.
 * @version 4.0
 * @author jerry_xia
 * @date January 12,2012
 */
public interface DiscreteDataDao {
	
	/**
	 * get max data id by monitor id.
	 * @param monitorId -int
	 * @return dataId - int
	 * @throws DataAccessException
	 */
	public int getMaxDataKeyByMonitorId(final int monitorId) throws DataAccessException;
	
	/**
	* add discrete data.
	* @param discreteData -DiscreteData
	* @return key -int
	* @throws DataAccessException
	*/
	public int addDiscreteData(final DiscreteData discreteData) throws DataAccessException;
	
	/**
	* add chart data.
	* @param chartData -ChartData
	* @return result -int
	* @throws DataAccessException
	*/
	public int addChartData(final ChartData chartData) throws DataAccessException;
	
	/**
	* get discrete data by data id.
	* @param dataId -int
	* @return discreteData -DiscreteData
	* @throws DataAccessException
	*/
	public DiscreteData getDiscreteDataByDataKey(final int dataId) throws DataAccessException;
	
	/**
	* get fourteen discrete datas before data key by monitor id and chart type and revision.
	* @param monitorId -int
	* @param chartType -String
	* @param revision -int
	* @param dataKey -int
	* @throws DataAccessException
	*/
	public List<DiscreteData> getFourteenDiscreteDatasBeforeDataKey(final int monitorId, final String chartType, final int revision,
		final int dataKey) throws DataAccessException;
	
	/**
	* get max revision discrete datas by monitor id and chart type.
	* @param monitorId -int
	* @param chartType -String
	* @throws DataAccessException
	*/
	public List<DiscreteData> getMaxRevisionDiscreteDatasByMonitorIdAndChartType(final int monitorId, final String chartType) throws DataAccessException ;
	
	/**
	* get last discrete data by monitor id and data user.
	* @param monitorId -int
	* @param dataUser -int
	* @throws DataAccessException
	*/
	public List<DiscreteData> getLastDiscreteDataByMonitorIdAndDataUser(final int monitorId, final int dataUser , final String netuserId) throws DataAccessException;
	
	/**
	* get chart key by data key and chart type.
	* @param dataKey -int
	* @param chartType -String
	* @return chartKey -int
	* @throws DataAccessException
	*/
	public int getChartKeyByDataKeyAndChartType(final int dataKey, final String chartType) throws DataAccessException;
	
	/**
	* get discrete datas by monitor id and date .
	* @param monitorId -int
	* @param startDate -Date
	* @param endDate -Date
	* @param dataStatus -int
	* @param dataUser -int
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getDiscreteDatasByMonitorNameAndDate(final int monitorId, final long startDate, final long endDate, final int dataStatus, final int dataUser) throws DataAccessException;
	
	/**
	*  get current page discrete datas by monitor id and date .
	* @param start -int
	* @param limit -int
	* @param monitorId -int
	* @param startDate -Date
	* @param endDate -Date
	* @param dataStatus -int
	* @param dataUser -int
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getCurrentPageDiscreteDatasByMonitorNameAndDate(int start,int limit,final int monitorId, final long startDate, final long endDate, final int dataStatus, final int dataUser) throws DataAccessException;
	
	/**
	* update discrete data .
	* @param discreteData -DiscreteData
	* @return result -int
	* @throws DataAccessException
	*/
	public int updateDiscreteData(final DiscreteData discreteData) throws DataAccessException;
	
	/**
	* update data status .
	* @param dataId -int
	* @param dataStatus -int
	* @return result -int
	* @throws DataAccessException
	*/
	public int updateDataStatus(final int dataId,final int dataStatus) throws DataAccessException;

	/**
	 * Pareto data into database
	 * @param paretoData pareto bean map
	 * @return sql return result
	 */
	public int addParetoData( ParetoData paretoData )  ;
	
	/**
	 * 
	 * @param paretoData
	 * @return
	 */
	public int addParetoDatas( List<ParetoData> paretoDatas )  ;

	/**
	 * Select pareto data,accord user select monito/begindate/enddate to group spc_pareto_data table  by defectcode and fetch 10
	 * record which are in the front
	 * @param monitorId monitor key
	 * @param beginDate begin date
	 * @param endDate end date
	 * @return the data which will be used by pareto 
	 */
	public List<ParetoData> getParetoDatas( int monitorId ,int beginDate , int endDate );
	
	/**
	 * 
	 * @param monitorId
	 * @param beginDate
	 * @param endDate
	 * @param defectcode defect code
	 * @return
	 */
	public int  getTotalParetoSNByDefectCode( int monitorId , int beginDate , int endDate , String defectcode );
	/**
	 * 
	 * @param monitorId
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	public List<ParetoData> getParetoSNByTime(final int monitorId ,int beginDate ,int endDate,int start , int limit,String netuserId) ;
	
	/**
	 * 
	 * @param monitorId
	 * @param beginDate
	 * @param endDate
	 * @param defectcode
	 * @return
	 */
	public List<ParetoData>  getOnePageParetoSNByDefectCode( int monitorId , int beginDate , int endDate , String defectcode , int start , int limit ,String netuserId );
	
	/**
	 * After display the top 10 defectcode in Web,User would view the defectcode contain which serial number
	 * @param monitorId monitor key 
	 * @param beginDate begin date
	 * @param endDate end date
	 * @param defectcode user click the defectcode then will select defectcode 
	 * @param common TODO
	 * @return  the serial number accord user select defectcode and begin date,end date
	 */
	public List<ParetoData> getAllParetoSNByDefectCode( int monitorId , int beginDate , int endDate , String defectcode, boolean common ,String netuserId );

	/**
	 * 
	 * @param monitorId
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	public int getTotalParetoSNByTime(int monitorId, int beginDate,int endDate);

	/**
	 * 
	 * @param spcRelParetoDataException
	 * @return
	 */
	public int addSpcRelParetoDataException( SpcRelParetoDataException spcRelParetoDataException ) ;

	/**
	 * 
	 * @param spcParetoException
	 * @return
	 */
	public int addSpcParetoException( SpcParetoException spcParetoException )  ;

	/**
	 * 
	 * @param monitorId
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public List<ParetoData> getParetoExceptionData(  String  netuserId,  int monitorId,long startDate, long endDate );

	/**
	 * 
	 * @param spcParetoExceptionKey
	 * @return
	 */
	public SpcParetoException getSpcParetoExceptionByKey( int spcParetoExceptionKey );

	/**
	 * 
	 * @param spcParetoException
	 * @return
	 */
	public int updateSpcParetoException(SpcParetoException spcParetoException);

	/**
	 * 
	 * @param monitorId
	 * @param dataKey
	 * @return
	 */
	public int getTotalParetoSNByParetoDataKey( int dataKey);

	/**
	 * 
	 * @param monitorId TODO
	 * @param dataKey
	 * @param start
	 * @param limit
	 * @param monitorId
	 * @return
	 */
	public List<ParetoData> getOnePageParetoSNByParetoDataKey( 	int monitorId, int dataKey, int start, int limit ,String netuserId);

	/**
	 * get discrete datas by monitor id and chart type and last data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @return List<DiscreteData> - discreteDataList
	 * @throws DataAccessException
	 */
	public List<DiscreteData> getDiscreteDatasByMonitorIdAndChartTypeAndLastDataId(final int monitorId, final String chartType, final int lastDataId) throws DataAccessException;
	
	/**
	 * get discrete datas by monitor id and chart type and last data id and next data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @param nextDataId -int
	 * @return List<DiscreteData> - discreteDataList
	 * @throws DataAccessException
	 */
	public List<DiscreteData> getDiscreteDatasByMonitorIdAndChartTypeAndLastDataIdAndNextDataId(final int monitorId, final String chartType, final int lastDataId, final int nextDataId) throws DataAccessException;
	
	/**
	* get discrete datas by latest points with current revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @param latestPoints -int
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getDiscreteDatasByLatestPointsWithCurrentRevision(final int monitorId, final String chartType, final int lastDataId, final int latestPoints) throws DataAccessException;
	
	/**
	* get discrete datas by latest points with old revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @param nextDataId -int
	* @param latestPoints -int
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getDiscreteDatasByLatestPointsWithOldRevision(final int monitorId, final String chartType, final int lastDataId, final int nextDataId, final int latestPoints) throws DataAccessException;
	
	/**
	* get discrete datas by date with current revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @param startDate -Date
	* @param endDate -Date
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getDiscreteDatasByDateWithCurrentRevision(final int monitorId, final String chartType, final int lastDataId, 
			final long startDate, final long endDate) throws DataAccessException;
	
	/**
	* get discrete datas by date with old revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @param nextDataId -int
	* @param startDate -Date
	* @param endDate -Date
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getDiscreteDatasByDateWithOldRevision(final int monitorId, final String chartType, final int lastDataId, 
			final int nextDataId, final long startDate, final long endDate) throws DataAccessException;
	
	/**
	 * get last fifteen discrete datas by monitor id and chart type and last data id.
	 * @param monitorId -int
	 * @param chartType -String
	 * @param lastDataId -int
	 * @return List<ContinuousData> - discreteDataList
	 * @throws DataAccessException
	 */
	public LinkedList<DiscreteData> getLastFifteenDiscreteDatasByChartTypeAndMonitorIdAndLastDataId(final int monitorId, final String chartType,
			final int lastDataId) throws DataAccessException;

	/**
	 * 
	 * @param datas
	 * @return
	 */
	public int addSpcRelParetoDataExceptions(	List<SpcRelParetoDataException> datas);
	
	/**
	* get current page discrete datas by chart type and current revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @param limit -int
	* @param start -int
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getCurrentPageDiscreteDatasByChartTypeAndCurrentRevision(final int monitorId, final String chartType, final int lastDataId, final int limit , final int start) throws DataAccessException;
	
	/**
	* get current page discrete datas by chart type and revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @param nextDataId -int
	* @param limit -int
	* @param start -int
	* @return List<DiscreteData> - discreteDataList
	* @throws DataAccessException
	*/
	public List<DiscreteData> getCurrentPageDiscreteDatasByChartTypeAndRevision(final int monitorId, final String chartType, final int lastDataId, final int nextDataId, final int limit , final int start) throws DataAccessException;
	
	/**
	* get count discrete datas by chart type and revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @return count - int
	* @throws DataAccessException
	*/
	public int getCountDiscreteDatasByChartTypeAndCurrentRevision(final int monitorId, final String chartType, final int lastDataId) throws DataAccessException;
	
	/**
	* get count discrete datas by chart type and revision.
	* @param monitorId -int
	* @param chartType -String
	* @param lastDataId -int
	* @param nextDataId -int
	* @return count - int
	* @throws DataAccessException
	*/
	public int getCountDiscreteDatasByChartTypeAndRevision(final int monitorId, final String chartType, final int lastDataId, final int nextDataId) throws DataAccessException;

	/**
	 * user  createTime to fetch pareto,because createTime is second
	 * @param monitorId
	 * @param createTime system set one batch data date.
	 * @return
	 */
	public List<ParetoData> getParetoDatasByCreateTime( int monitorId , long createTime );
 
	/**
	 * change aDateTime to display string
	 * @param seconds aDateTime
	 * @param netuserId netUeerId
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public String changeSecondToFormatTime( int seconds , String netuserId );

	public int updateDiscreteHiddenData(DiscreteData discreteData);

	public List<DiscreteData> getNoDealByTimeData(int monitorId);

	public void fillNoDealByTimeDataADateTime(DiscreteData discreteData);

	public List<DiscreteData> getNoDealByTimeData2(int monitorId);

	public DiscreteData getLastDiscreteDataByMonitorId( int monitorId);

}
